﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace Speedy
{
    public partial class frmPlasiyer : XtraForm
    {
        public frmPlasiyer()
        {
            InitializeComponent();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            dbMerchant m = new dbMerchant();
            m.code.SetValue(txtKod.Text);
            m.name.SetValue(txtAd.Text);
            m.Save();
            m.code.Alias = "Plasiyer Kodu";
            m.name.Alias = "Plasiyer Adı";
            gridControl1.DataSource = m.AllData();
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            dbMerchant m = new dbMerchant();
            m.code.SetValue(txtKod.Text);
            m.Remove();
            m.code.Alias = "Plasiyer Kodu";
            m.name.Alias = "Plasiyer Adı";
            gridControl1.DataSource = m.AllData();
        }

        private void frmPlasiyer_Load(object sender, EventArgs e)
        {
            dbMerchant m = new dbMerchant();
            m.code.Alias="Plasiyer Kodu";
            m.name.Alias="Plasiyer Adı";
            gridControl1.DataSource = m.AllData();
        }


        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (gridView1.RowCount > 0 && gridView1.Columns.Count > 0)
                SelectRecord(e.FocusedRowHandle);
        }

        void SelectRecord(int row)
        {
            txtKod.Text = gridView1.GetRowCellValue(row, gridView1.Columns["Plasiyer Kodu"]).ToString();
            txtAd.Text = gridView1.GetRowCellValue(row, gridView1.Columns["Plasiyer Adı"]).ToString();
        }
        private void gridControl1_Click(object sender, EventArgs e)
        {
            if (gridView1.RowCount > 0 && gridView1.Columns.Count > 0)
                SelectRecord(gridView1.FocusedRowHandle);
        }

    }
}
